from apps.patent.patent.spiders.account.core.patent_account_login import CpOnlineLogin
from utils.proxies_tools import get_company_ip_crawler_by_api
from utils.user_pool.base_user_pool import GoldUser
from utils.user_pool.gold_user_pool import GoldUserPool


class PatentUserPool(GoldUserPool):

    def login(self, user):
        """
        登录 生产cookie
        """
        username = user.username
        password = user.password
        proxies = get_company_ip_crawler_by_api(static=True)
        cls = CpOnlineLogin(proxies=proxies)
        auth_code = cls.login(username, password)
        user.cookies = {"Authorization": f"Bearer {auth_code}"}
        user.headers = cls.headers
        return user


users = [
    GoldUser(max_use_times=(24 * 60 * 60) / 4 + 1, use_interval=4, username="15869175424", password="fuppyfSupfuk!1"),
    GoldUser(max_use_times=(24 * 60 * 60) / 4 + 1, use_interval=4, username="15670813638", password="Hugofking@123"),
]
PATENT_USER_POOL = PatentUserPool(redis_key="patent_user_pool", users=users, keep_alive=False)

if __name__ == "__main__":
    print(PATENT_USER_POOL.run("15670813638"))
